package com.jiepos.mpos.biz.customer.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jiepos.mpos.biz.affix.service.AppAffixInfService;
import com.jiepos.mpos.biz.customer.service.AppCustomerInfoService;
import com.jiepos.mpos.biz.customer.service.CustomBankcardInfoService;
import com.jiepos.mpos.biz.user.service.AppInsInfService;
import com.jiepos.mpos.common.entity.App_Custom_InfEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 会员信息功能维护控制层
 * 
 * @ProjectName: [mpos1]
 * @Package com.jiepos.mpos.biz.customer.controller
 * @author 肖志伟
 * @version 1.0
 * @since 2017年9月21日 下午2:36:20
 * @history（历次修订内容、修订人、修订时间等） @UpdateRemark [说明本次修改内容]
 * @Copyright (c) 2017 江苏杰博实信息技术有限公司
 */
@Controller
@RequestMapping("customerinfo")
public class AppCutomerInfoController extends BaseController {

	@Autowired
	private AppCustomerInfoService appCustomerInfoService;

	@Autowired
	private CustomBankcardInfoService customBankcardInfoService;

	@Autowired
	private AppAffixInfService appAffixInfService;

	@Autowired
	private AppInsInfService appInsInfService;

	/**
	 * 进入会员信息列表页界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/getCustomerInfoList.do")
	public ModelAndView getCustomerInfoList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView model = new ModelAndView("/module/customer/customerinfo/customerinfo_list");
		return super.getDetail(request, response, model);
	}

	/**
	 * 查询会员信息json数据
	 * 
	 * @param request
	 * @param pagination
	 * @param appCustomerInfEntity
	 * @param ins_name
	 * @param sup_custom_name
	 * @return
	 */
	@RequestMapping("/getCustomerInfoListJson.do")
	public @ResponseBody Map getCustomerInfoListJson(HttpServletRequest request, Pagination pagination,
			App_Custom_InfEntity appCustomerInfEntity, String ins_name, String sup_custom_name,String sup_custom_no,
													 String realname_auth_ts_start,String realname_auth_ts_end ) {
		return appCustomerInfoService.getCustomerInfoList(request, pagination, appCustomerInfEntity, ins_name,
				sup_custom_name,sup_custom_no,realname_auth_ts_start,realname_auth_ts_end);
	}

	/**
	 * 启用或停用
	 * 
	 * @param request
	 * @param response
	 * @param ins_uuid
	 * @return
	 */
	@RequestMapping("/updateCustomersUserSt.do")
	@ResponseBody
	public void enableIns(HttpServletRequest request, HttpServletResponse response, String user_st, String customer_uuids) {
		appCustomerInfoService.updateUserSt(customer_uuids, super.getLoginUser(request, response), user_st);
	}

	/**
	 * 获取会员上下级关系菜单树
	 * 
	 * @param ID
	 *            会员的uuid，如果有uuid则查找sup_custom_uuid 为该id的内容，没有则查找sup_custom_uuid
	 *            是空的
	 * @return
	 */
	@RequestMapping("/customerRelationTree_show.do")
	@ResponseBody
	public List<Map<String, Object>> getCustomerRelationTree(HttpServletRequest request, String ID, String searchText) {
		return appCustomerInfoService.getCustomerRelationTree(request, ID, searchText);
	}

	/**
	 * 获取会员详细信息
	 * 
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/getCustomerDetail.do")
	public ModelAndView getCustomerDetail(HttpServletRequest request, HttpServletResponse response,
			String custom_uuid) {
		ModelAndView modelAndView = new ModelAndView("/module/customer/customerinfo/customerinfo_detail");
		modelAndView.addObject("custom_uuid", custom_uuid);
		return super.getDetail(request, response, modelAndView);
	}

	/**
	 * 获取会员详细信息
	 * 
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/getCustomerCommonDetail.do")
	public ModelAndView getCustomerCommonDetail(HttpServletRequest request, HttpServletResponse response,
			String custom_uuid) {
		ModelAndView modelAndView = new ModelAndView("/module/customer/customerinfo/customerinfo_common_detail");
		if (!StringUtils.isEmpty(custom_uuid)) {
			Map customInfEntity = appCustomerInfoService.getCustomerInfoByUUID(custom_uuid);
			Map appCustomBankEntity = customBankcardInfoService.getCustomBankCard(custom_uuid);
			List<Map<String, Object>> picList = appAffixInfService.getCustomCertificatePic(custom_uuid);
			modelAndView.addObject("appCustomerInfEntity", customInfEntity);
			modelAndView.addObject("appCustomBankEntity", appCustomBankEntity);
			modelAndView.addObject("picList", picList);
		}
		return super.getDetail(request, response, modelAndView);
	}

	/**
	 * 获取会员详细信息
	 * 
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/showPicInfo.do")
	public ModelAndView showPicInfo(HttpServletRequest request, HttpServletResponse response, String custom_uuid,
			String picId) {
		ModelAndView modelAndView = new ModelAndView("/module/customer/customerinfo/customerinfo_pic_detail");
		if (!StringUtils.isEmpty(custom_uuid)) {
			List<Map<String, Object>> picList = appAffixInfService.getCustomCertificatePic(custom_uuid);
			modelAndView.addObject("picList", picList);
			modelAndView.addObject("picId", picId);
		}
		return super.getDetail(request, response, modelAndView);
	}

	/**
	 * 获取机构菜单树
	 * 
	 * @return
	 */
	@RequestMapping("/getODanInsTree.do")
	@ResponseBody
	public List<Map<String, Object>> getODanInsTree(HttpServletRequest request, String ID, String searchText) {
		return appInsInfService.getODanInsTree(request, ID, searchText);
	}

	/**
	 * 修改会员的APP所属机构
	 * 
	 * @return
	 */
	@RequestMapping("/modifyCustomInsUuid.do")
	@ResponseBody
	public Boolean modifyCustomInsUuid(HttpServletRequest request,HttpServletResponse response, String custom_uuids, String ins_cd) {
		return appCustomerInfoService.modifyCustomInsUuid(custom_uuids, super.getLoginUser(request, response), ins_cd);
	}

}
